﻿using System.Collections.Generic;
using System.Xml.Linq;
using Harvest.API.Model;

namespace Harvest.API
{

    public partial class Wrapper
    {

        /// <summary>
        /// Get all projects.
        /// </summary>
        /// <remarks>GET /projects</remarks>
        /// <returns></returns>
        public List<Project> GetProjects()
        {
            var data = Request(WebRequestMethodEnum.Get, "projects");
            var xDocument = XDocument.Parse(data);
            return xDocument.ToProjects();
        }

        /// <summary>
        /// Get an existing project.
        /// </summary>
        /// <remarks>GET /projects/#{project_id}</remarks>
        /// <param name="id"></param>
        /// <returns></returns>
        public Project GetProject(int id)
        {
            var data = Request(WebRequestMethodEnum.Get, "projects/" + id);
            var xDocument = XDocument.Parse(data);
            return xDocument.ToProject();
        }

        /// <summary>
        /// Delete an existing project.
        /// </summary>
        /// <remarks>DELETE /projects/#{project_id}</remarks>
        /// <param name="id"></param>
        /// <returns></returns>
        public string DeleteProject(int id)
        {
            var data = Request(WebRequestMethodEnum.Delete, "projects/" + id);
            return data;
        }

        /// <summary>
        /// Activate or deactivate an existing project.
        /// </summary>
        /// <remarks>PUT /projects/#{project_id}/toggle</remarks>
        /// <param name="id"></param>
        /// <returns></returns>
        public string ToggleProjectActive(int id)
        {
            var data = Request(WebRequestMethodEnum.Put, "projects/" + id + "/toggle");
            return data;
        }

        /// <summary>
        /// Update an existing project.
        /// </summary>
        /// <remarks>PUT /projects/#{project_id}</remarks>
        /// <param name="project"></param>
        /// <returns></returns>
        public string UpdateProject(Project project)
        {
            var data = Request(WebRequestMethodEnum.Put, "projects/" + project.Id, project.Serialize());
            return data;
        }

        /// <summary>
        /// Create a new project.
        /// </summary>
        /// <remarks>POST /projects</remarks>
        /// <param name="project"></param>
        /// <returns></returns>
        public string CreateProject(Project project)
        {
            var data = Request(WebRequestMethodEnum.Post, "projects", project.Serialize());
            return data;
        }

    }

}
